<?xml version="1.0" encoding="UTF-8"?>
<definitions id="definitions" 
  xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
  xmlns:camunda="http://camunda.org/schema/1.0/bpmn"
  targetNamespace="Examples">

  <error id="Error_1" errorCode="error1" name="error1"/>
  
  <process id="compensateProcess" isExecutable="true">

    <startEvent id="start" />

    <sequenceFlow sourceRef="start" targetRef="fork" />

    <parallelGateway id="fork" />

    <sequenceFlow sourceRef="fork" targetRef="bookHotel" />
    <sequenceFlow sourceRef="fork" targetRef="bookFlight" />

    <serviceTask id="bookHotel" camunda:expression="${true}">
      <multiInstanceLoopCharacteristics isSequential="true">
        <loopCardinality>5</loopCardinality>
      </multiInstanceLoopCharacteristics>
    </serviceTask>

    <boundaryEvent id="compensateBookHotelEvt" name="Boundary event" attachedToRef="bookHotel">
      <compensateEventDefinition />
    </boundaryEvent>

    <serviceTask id="undoBookHotel" isForCompensation="true"
      camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.UndoService">
      <extensionElements>
        <camunda:field name="counterName" stringValue="undoBookHotel" />
      </extensionElements>
    </serviceTask>  

    <serviceTask id="bookFlight" camunda:expression="${true}">
      <multiInstanceLoopCharacteristics isSequential="true">
        <loopCardinality>5</loopCardinality>
      </multiInstanceLoopCharacteristics>
    </serviceTask>

    <boundaryEvent id="compensateBookFlightEvt" name="Boundary event" attachedToRef="bookFlight">
      <compensateEventDefinition  />
    </boundaryEvent>

    <serviceTask id="undoBookFlight" isForCompensation="true"
      camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.UndoService">
      <extensionElements>
        <camunda:field name="counterName" stringValue="undoBookFlight" />
      </extensionElements>
    </serviceTask>

    <parallelGateway id="join" />

    <sequenceFlow sourceRef="bookHotel" targetRef="join" />
    <sequenceFlow sourceRef="bookFlight" targetRef="join" />
    <sequenceFlow sourceRef="join" targetRef="end" />

    <endEvent id="end" >
      <errorEventDefinition errorRef="Error_1"/>
    </endEvent>

    <subProcess id="eventSubProcess" triggeredByEvent="true">
    
      <startEvent id="startSubProcess" name="bookJourney">
        <errorEventDefinition errorRef="Error_1"/>
      </startEvent>
      
      <sequenceFlow sourceRef="startSubProcess" targetRef="bookSecondHotel" />
      
      <serviceTask id="bookSecondHotel" camunda:expression="${true}">
        <multiInstanceLoopCharacteristics isSequential="true">
          <loopCardinality>5</loopCardinality>
        </multiInstanceLoopCharacteristics>
      </serviceTask>
  
      <boundaryEvent id="compensateBookSecondHotelEvt" name="Boundary event" attachedToRef="bookSecondHotel">
        <compensateEventDefinition  />
      </boundaryEvent>
  
      <serviceTask id="undoBookSecondHotel" isForCompensation="true"
        camunda:class="org.camunda.bpm.engine.test.bpmn.event.compensate.helper.UndoService">
        <extensionElements>
          <camunda:field name="counterName" stringValue="undoBookSecondHotel" />
        </extensionElements>
      </serviceTask>
      
      <sequenceFlow sourceRef="bookSecondHotel" targetRef="throwCompensate"/>
      
      <intermediateThrowEvent id="throwCompensate">
        <compensateEventDefinition activityRef="bookSecondHotel" />
      </intermediateThrowEvent>      
      
      <sequenceFlow sourceRef="throwCompensate" targetRef="endSubProcess" />
      
      <endEvent id="endSubProcess" />

      <association associationDirection="One" sourceRef="compensateBookSecondHotelEvt" targetRef="undoBookSecondHotel" />
    </subProcess>
  
    <association associationDirection="One" sourceRef="compensateBookHotelEvt" targetRef="undoBookHotel" />
    <association associationDirection="One" sourceRef="compensateBookFlightEvt" targetRef="undoBookFlight" />
  </process>

</definitions>
